// stores/counter.js
import { defineStore } from 'pinia'
import { encryptedSerializer } from '@/utils/jiami'
interface CounterState {
    count: number
    name: string
}

export const useCounterStore = defineStore('counter', {
    state: (): CounterState => ({
        count: 0,
        name: 'Eduardo',
    }),
    getters: {
        doubleCount: (state) => state.count * 2,
        doubleCountPlusOne(): number {
            return this.count + 1
        }
    },
    actions: {
        increment() {
            this.count++
        },
        randomizeCounter() {
            this.count = Math.round(100 * Math.random())
        }
    },
    persist: {
        serializer: encryptedSerializer,
        enabled: true,
        storage: localStorage
    } as any
})
export type StoreType = ReturnType<typeof useCounterStore>;

interface AppState {
    locale: string
}

export const useAppStore = defineStore('app', {
    state: (): AppState => ({
        locale: 'zh',
    }),
    actions: {
        setLocale(lang: string) {
            this.locale = lang
        }
    },
    persist: true // 启用持久化
})